package com.example.myapplication.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.myapplication.ComData;
import com.example.myapplication.R;
import com.example.myapplication.adapter.FragmentAdapter;
import com.example.myapplication.fragment.fragment2.City_Fragment;
import com.example.myapplication.fragment.fragment2.Find_Fragment;
import com.example.myapplication.fragment.fragment2.atten_fragment;
import com.example.myapplication.video.video_sift.SiftVideoFragment;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class BlankFragment extends Fragment {

    private View view;
    private CommonTabLayout mainCom;
    private ArrayList<CustomTabEntity> tabEntitys = new ArrayList<>();
    private ImageView fragLiebiao;
    private ImageView fragSousuo;
    private ViewPager fragVip;
    private FragmentAdapter fragmentAdapter;
    private List<Fragment> list = new ArrayList<>();
    private SlidingMenu slidingMenu;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_blank, container, false);
        initView();
        initData();

        return view;
    }

    private void initView() {
        mainCom = (CommonTabLayout) view.findViewById(R.id.main_com);
        fragLiebiao = (ImageView) view.findViewById(R.id.frag_liebiao);
        fragSousuo = (ImageView) view.findViewById(R.id.frag_sousuo);
        fragVip = (ViewPager) view.findViewById(R.id.frag_vip);
        slidingMenu = new SlidingMenu(getContext());


    }

    private void initData() {
        list.add(new Find_Fragment());
        list.add(new SiftVideoFragment());

        list.add(new City_Fragment());
        fragmentAdapter = new FragmentAdapter(getActivity().getSupportFragmentManager(), list);
        fragVip.setAdapter(fragmentAdapter);
        fragVip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mainCom.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        fragLiebiao.setImageResource(R.mipmap.liebiao);
        fragSousuo.setImageResource(R.mipmap.sousuo);
        tabEntitys.add(new ComData("同城", 0, 0));
        tabEntitys.add(new ComData("关注", 0, 0));
        tabEntitys.add(new ComData("发现", 0, 0));

        mainCom.setTabData(tabEntitys);
        mainCom.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                fragVip.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        //添加slide
        slidingMenu.setMode(SlidingMenu.LEFT);
        slidingMenu.setBehindOffset(200);
        slidingMenu.setMenu(R.layout.sliding);
        slidingMenu.attachToActivity(getActivity(), SlidingMenu.SLIDING_CONTENT);

        slidingMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                slidingMenu.showContent();
            }
        });

        fragLiebiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                slidingMenu.showMenu();
            }
        });

    }


}
